<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>虚拟环境管理</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/common.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/index.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/manage-venvs.css') }}">
</head>
<body>
    <div class="header-nav">
        <h1>虚拟环境管理</h1>
        <div class="nav-links">
            <a href="{{ url_for('home') }}" class="nav-btn">返回首页</a>
            <a href="{{ url_for('manage_scripts') }}" class="nav-btn">脚本管理</a>
        </div>
    </div>

    {% with messages = get_flashed_messages() %}
        {% if messages %}
        <ul class="flash-messages">
            {% for message in messages %}
            <li class="flash-message">{{ message }}</li>
            {% endfor %}
        </ul>
        {% endif %}
    {% endwith %}

    <div class="container">
        <h2>创建新虚拟环境</h2>
        <form action="{{ url_for('create_venv_route') }}" method="post" class="create-venv-form">
            <div class="form-group">
                <label for="venv_name">虚拟环境名称:</label>
                <input type="text" id="venv_name" name="venv_name" required>
            </div>
            <button type="submit" class="create-btn">创建虚拟环境</button>
        </form>
    </div>

    <div class="container">
        <h2>已有虚拟环境</h2>
        <div class="venv-list">
            {% for venv in venvs %}
            <div class="venv-item">
                <div class="venv-header">
                    <div class="venv-info">
                        <h3>{{ venv.name }}</h3>
                        <div class="venv-details">
                            <span>Python版本: {{ venv.python_version }}</span>
                            <span>路径: {{ venv.path }}</span>
                        </div>
                    </div>
                    <div class="venv-actions">
                        <a href="{{ url_for('delete_venv', name=venv.name) }}" 
                           onclick="return confirm('确定要删除这个虚拟环境吗？')" 
                           class="delete-btn">删除虚拟环境</a>
                    </div>
                </div>
                
                <div class="package-section">
                    <div class="package-header" onclick="togglePackageList('{{ venv.name }}')">
                        <div class="package-title">
                            <span class="package-toggle"></span>
                            <h4>已安装的包 ({{ venv.packages|length }})</h4>
                        </div>
                        <div class="package-actions">
                            <input type="text" class="package-input" id="package-input-{{ venv.name }}" 
                                   placeholder="输入包名称">
                            <button onclick="installPackage('{{ venv.name }}')" class="install-btn">安装</button>
                        </div>
                    </div>
                    <div id="package-list-{{ venv.name }}" class="package-list">
                        {% for pkg in venv.packages %}
                        <div class="package-item">
                            <span class="package-name">{{ pkg.name }} <span class="package-version">({{ pkg.version }})</span></span>
                            <button onclick="uninstallPackage('{{ venv.name }}', '{{ pkg.name }}')" 
                                    class="uninstall-btn">卸载</button>
                        </div>
                        {% endfor %}
                    </div>
                </div>
            </div>
            {% else %}
            <p class="no-venv">暂无虚拟环境</p>
            {% endfor %}
        </div>
    </div>

    <div id="statusMessage" class="status-message"></div>

    <script src="{{ url_for('static', filename='js/manage-venvs.js') }}"></script>
</body>
</html> 